﻿using Southern.Common.Cache;
using Southern.Common.Helpers;
using Microsoft.Practices.TransientFaultHandling;

namespace Southern.Models.Southern.Base
{
    public abstract class RepositoryBase
    {

        protected IDatabase DB { get; private set; }
        protected ICache Cacher { get; private set; }

        /// <summary>
        /// The retry policy for SqlAzure
        /// See more at: http://msdn.microsoft.com/en-us/library/hh680900(v=pandp.50).aspx
        /// </summary>
        protected RetryPolicy SqlRetryPolicy { get; private set; }
        public RepositoryBase(IDatabase db, ICache cacher)
        {
            this.DB = db;
            this.Cacher = cacher;
            this.SqlRetryPolicy = RetryPolicy.NoRetry;
            this.SqlRetryPolicy.Retrying +=
                (sender, args) => TraceHelper.TraceInformation(
                    "Retry - Count:{0}, Delay:{1}, Exception:{2}",
                    args.CurrentRetryCount,
                    args.Delay,
                    args.LastException
               );
        }
    }
}